<template>
	<view v-if="relatedListAll.length > 2" class="relatedBox">
		<view style="width: 100%;margin-top: 0;" class="isTitle">
			<view>{{title}}</view>
			<view style="font-size: 28rpx;color: #B3B3B3;font-weight: normal;">大家都爱看</view>
		</view>
		<view class="videoLineBox">
			<view v-for="(mayItem, mayIndex) in relatedList" @click="toDetail(mayItem,'mayLike')" class="videoBox">
				<image lazy-load class="videoImg" :src="mayItem.coverImgUrl"></image>
				<view style="text-align: center;color: #333333;font-size: 30rpx;margin-top: 8rpx;" class="clamp">{{ mayItem.title }}</view>
				<view style="text-align: center;color: #B3B3B3;font-size: 26rpx;margin-top: 2rpx;">
					{{ mayItem.finish ? '已完结共' + mayItem.updateOfEpisodes + '集' : '更新至第' + mayItem.updateOfEpisodes + '集' }}
				</view>
			</view>
			<view v-if="relatedList.length % 3 == 2" class="videoBox">
				<view class="videoImg"></view>
			</view>
		</view>
		<view @click="isChangeRelated" v-if="relatedListAll.length > 3" class="changeBox">
			<image style="width: 30rpx;height: 30rpx;margin-right: 14rpx;" src="https://res.qiguoread.com/staticResources/fellow_townsman/image/uni/icon_isChange.png"></image>
			<text style="font-size: 28rpx;color: #666666;">换一换</text>
		</view>
	</view>
</template>

<script>
	export default {
		props:{
			title:{
				default:'猜你喜欢',
				type:String
			},
			list:{
				default:()=>{
					return []
				},
				type:Array
			}
		},
		data() {
			return {
				relatedListAll:[],
				relatedList:[],
				relatedIndex: 0
			}
		},
		methods: {
			isChangeRelated() {
				this.$uma && this.$uma.trackEvent('Ume_page1_control', {
					name: 'Ume_page1_control_change'
				});
				this.getRelatedList();
			},
			getBannerList() {
				this.relatedListAll = this.list.map((item, index) => {
					item = item.contentInfo;
					item['index'] = index;
					return item;
				});
				this.getRelatedList();
				// this.zwyRequest({
				// 	url: '/cdp/index/compilations/related',
				// 	noErr: true
				// }).then(res => {
				// 	console.log('related', res);
				// 	this.relatedListAll = res;
				// 	this.getRelatedList();
				// });
			},
			getRelatedList() {
				this.$uma && this.$uma.trackEvent('Ume_ex_PV', {
					name: 'Umk_page1_like'
				});
				let tempList = [];
				let nowLength = this.relatedListAll.length;
				if (nowLength == 0) return;
				let allList = JSON.parse(JSON.stringify(this.relatedListAll));
				allList = allList.splice(this.relatedIndex, 3);
				console.log('allList', allList,'this.relatedIndex',this.relatedIndex);
				if(allList.length < 3){
					this.relatedIndex = 0;
					let needNum = 3 - allList.length ;
					for(let i = 0 ; i<needNum;i++){
						allList.push(this.relatedListAll[i]);
					}
					this.relatedIndex += needNum;
				}else{
					this.relatedIndex += 3;
				}
				
				this.relatedList = allList;
				if (this.relatedIndex >= nowLength) this.relatedIndex = 0;
			},
			toDetail(item,type) {
				if(type =='mayLike'){
					this.$uma && this.$uma.trackEvent('Ume_skip', {
						name: 'Ume_skip_page1_like'
					});
				}else if(type == 'hot'){
					this.$uma && this.$uma.trackEvent('Ume_skip', {
						name: 'Ume_skip_page1_hot'
					});
				}
				console.log('item', item);
				this.zwyRouter(`/pages/video/video?fakeId=${item.fakeId}&compilationId=${item.compilationId}`);
			}
		},
		created() {
			this.getBannerList();
		}
	}
</script>

<style lang="scss" scoped>
	.isTitle {
		display: flex;
		align-items: center;
		justify-content: space-between;
		margin-bottom: 22rpx;
		width: 96vw;
		font-size: 32rpx;
		font-weight: bold;
		color: #333333;
		margin-top: 18rpx;
	}
	.changeBox {
		width: 649rpx;
		height: 80rpx;
		border-radius: 80rpx;
		margin-top: 24rpx;
		background-color: white;
		display: flex;
		align-items: center;
		justify-content: center;
	}
	.relatedBox {
		margin-bottom:30rpx ;
		border-radius: 15rpx;
		padding: 25rpx 25rpx 38rpx 25rpx;
		background-color: #f6f6f6;
		width: 95vw;
		box-sizing: border-box;
	}
	.videoLineBox {
		display: flex;
		justify-content: space-between;
		align-items: center;
		.videoBox {
			position: relative;
			width: 27vw;
			.videoImg {
				width: 27vw;
				height: 290rpx;
				border-radius: 13rpx;
			}
			overflow: hidden;
		}
	}
</style>
